<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>flask的for循环</title>
</head>
<body>
    <ul>
        {% for user in users|reverse %}
            <li>{{ user }}</li>
        {% else %}
            <li>没有任何值</li>
        {% endfor %}
    </ul>
    <table>
        <thead>
            <tr>
                <th>用户名</th>
                <th>年龄</th>
                <th>国家</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <!-- <td>{{ person.username }}</td> -->
                <!-- <td>{{ person.age }}</td> -->
                <!-- <td>{{ person.country }}</td> -->
                
                <!-- 取person字典的键和值有下列几种方法: -->
                <!-- 第一种方法: items -->
                <!-- {% for key,value in person.items() %} -->
                    <!-- <td>{{ value }}</td> -->
                <!-- {% endfor %} -->

                <!-- 第二种方法: keys -->
                <!-- {% for key in person.keys() %} -->
                    <!-- <td>{{ key }}</td> -->
                <!-- {% endfor %} -->

                <!-- 第三种方法: values -->
                {% for value in person.values() %}
                    <td>{{ value }}</td>
                {% endfor %}
            </tr>
        </tbody>
    </table>

    <table>
        <thead>
            <tr>
                <th>书名</th>
                <th>作者</th>
                <th>价格</th>
                <th>总数</th>
            </tr>
        </thead>
        <tbody>
            {% for book in books %}
                {% if loop.first %}
                    <tr style="background: red;">
                {% elif loop.last %}
                    <tr style="background: pink">
                {% else %}
                    <tr>
                {% endif %}
                    <!-- <td>{{ loop.index }}</td> -->
                    <td>{{ loop.index0 }}</td>
                    <td>{{ book.name }}</td>
                    <td>{{ book.author }}</td>
                    <td>{{ book.price }}</td>
                    <td>{{ loop.length }}</td>
                </tr>
            {% endfor %}
        </tbody>
    </table>
    <hr>
    
    <table border="1">
        <tbody>
            {% for x in range(1,10) %}
                <tr>
                    <!-- {% for y in range(1,x+1) %} -->
                    {% for y in range(1,10) if y <= x %}
                        <td>{{ y }}*{{ x }}={{ x*y }}</td>
                    {% endfor %}
                </tr>
            {% endfor %}
        </tbody>
    </table>
</body>
</html>